package com.naza.rpc.util;

import com.alibaba.nacos.api.naming.pojo.Instance;
import com.naza.rpc.model.ServiceInstance;

public class InstanceUtil {
    public static Instance createInstance(ServiceInstance serviceInstance){
        Instance instance = new Instance();
        instance.setIp(serviceInstance.getIp());
        instance.setPort(serviceInstance.getPort());
        instance.setServiceName(serviceInstance.getServiceName());
        instance.setInstanceId(serviceInstance.getId());
        instance.setClusterName(serviceInstance.getApplicationName());
        instance.setHealthy(true);
        instance.setEnabled(true);
        instance.setWeight(1.0); //default 1.0
        return instance;
    }

    public static ServiceInstance transfer(Instance instance){
        ServiceInstance serviceInstance = new ServiceInstance();
        serviceInstance.setApplicationName(instance.getClusterName());
        serviceInstance.setId(instance.getInstanceId());
        serviceInstance.setIp(instance.getIp());
        serviceInstance.setPort(instance.getPort());
        serviceInstance.setServiceName(instance.getServiceName());
        return serviceInstance;
    }
}
